import { Column, Entity, JoinTable, ManyToMany, OneToMany } from 'typeorm';
import { BaseEntity } from '../../../common/baseEntity/index';
import { Role } from '../../role/entities/role.entity';
import { ArticleLike } from '../../article/entities/article-like.entity';
import { ArticleComment } from '../../article/entities/article-comment.entity';

export enum UserGender {
  未知 = -1,
  女 = 0,
  男 = 1,
}

export enum UserStatus {
  正常 = 1,
  禁用 = 0,
}

export enum IsDeleted {
  删除 = 1,
  未删除 = 0,
}

// 用户表
@Entity('user')
export class User extends BaseEntity {
  @Column({
    type: 'varchar',
    length: 50,
    unique: true,
    comment: '用户名、账号',
  })
  username: string;

  @Column({ type: 'varchar', length: 255, comment: '密码' })
  password: string;

  @Column({
    type: 'varchar',
    name: 'nickname',
    length: 50,
    nullable: true,
    comment: '用户昵称',
  })
  nickname: string;

  @Column({
    type: 'int',
    // enum: UserGender,
    default: -1,
    comment: '性别',
  })
  gender: number;

  @Column({ type: 'varchar', length: 255, nullable: true, comment: '用户头像' })
  avatar: string;

  @Column({
    type: 'varchar',
    length: 50,
    nullable: true,
    unique: true,
    comment: '用户联系方式',
  })
  phone: string;

  @Column({ type: 'varchar', length: 50, nullable: true, comment: '电子邮箱' })
  email: string;

  @Column({ type: 'varchar', length: 300, nullable: true, comment: '备注' })
  remark: string;

  @Column({
    type: 'int',
    // enum: UserStatus,
    default: 1,
    comment: '状态',
  })
  status: number;

  @Column({
    type: 'int',
    name: 'is_deleted',
    // enum: IsDeleted,
    default: 0,
    comment: '逻辑删除',
  })
  isDeleted: number;

  @Column({ type: 'varchar', length: 50, nullable: true, comment: '创建人' })
  creator: string;

  @ManyToMany(() => Role)
  @JoinTable({ name: 'user_role_relation' })
  roles: Role[];

  // 用户与点赞一对多关系
  @OneToMany(() => ArticleLike, (articleLike) => articleLike.user)
  articleLikes: ArticleLike[];

  // 用户与评论一对多关系
  @OneToMany(() => ArticleComment, comment => comment.user)
  comments: ArticleComment[];
}
